package edu.zzuli.model.xt.pzzc.gnsq;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import edu.zzuli.common.Pagination;
import edu.zzuli.model.core.JqGridBaseAction;
import edu.zzuli.model.orm.po.GG_CZLB;
import edu.zzuli.model.xt.pzzc.gnsq.iface.GnsqService;

/**
 * @author tianshaojie
 * @date 2011-1-10
 * @discription : 
 */
@SuppressWarnings("serial")
@Controller
public class GnsqMainFrameAction extends JqGridBaseAction<GG_CZLB>{
	
	@Resource
	private GnsqService gnsqService;
	
	private GG_CZLB gg_czlb_cx = new GG_CZLB();
	
//	@Resource
//	private GG_CZLBDao gg_czlbDao;
	
	private String ajaxResult;
	
	public String execute() {
		return this.refreshGridModel();
	}
	
	@Override
	public List<GG_CZLB> listResults(Pagination pagination) {
		String sql = "select id,lbmc,sm from gg_czlb where jgbh = '0001'";
		if (gg_czlb_cx.getLbmc() != null && !"".equals(gg_czlb_cx.getLbmc())) {
			sql += " and lbmc like '%" + gg_czlb_cx.getLbmc() + "%'";
		}
		if (gg_czlb_cx.getSm() != null && !"".equals(gg_czlb_cx.getSm())) {
			sql += " and sm like '%" + gg_czlb_cx.getSm() + "%'";
		}
		sql += " order by id desc";
		return gnsqService.selectSplit(sql, pagination);
	}
	
	/*@Override
	public List listResults(int from, int length) {
		List<GG_CZLB> results = Collections.emptyList();
		results = this.gg_czlbDao.getGG_CZLBList(from, length);//from = rows * (page - 1);  length = rows;
		return results;
	}
	
	@Override
	public int getResultSize() {
		String sql = "select count(*) from gg_czlb";
		return this.gnsqService.getIntBySql(sql);
	}*/
	
	/*public String execute() {
		return this.refreshGridModel();
		int page =Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));
		int rows = Integer.parseInt(ServletActionContext.getRequest().getParameter("rows"));
		String sql = "select count(*) from gg_czlb";
		this.total = this.gnsqService.getIntBySql(sql);
		List<GG_CZLB> czlbList = this.gg_czlbDao.getGG_CZLBList((page - 1) * rows, rows);
//		List<GG_CZLB> czlbList = gnsqService.getGG_CZLB();
		this.rows = new ArrayList<Object>();
		for (GG_CZLB gg_czlb : czlbList) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("id", gg_czlb.getId());
			map.put("lbmc", gg_czlb.getLbmc());
			map.put("sm", gg_czlb.getSm());
			this.rows.add(map);
		}
		return "success";
	}*/
	
	public String delete() {
		String ids = ServletActionContext.getRequest().getParameter("id");
		try {
			if (ids != null && !"".equals(ids)) {
				this.gnsqService.deleteGG_CZLB(ids);
				this.ajaxResult = "success";
			} else {
				this.ajaxResult = "error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxResult = "error";
		}
		return this.ajaxResult;
	}

	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public String getAjaxResult() {
		return ajaxResult;
	}

	public void setGg_czlb_cx(GG_CZLB gg_czlb_cx) {
		this.gg_czlb_cx = gg_czlb_cx;
	}

	public GG_CZLB getGg_czlb_cx() {
		return gg_czlb_cx;
	}

}
